<?php
/**
 * Created by PhpStorm.
 * User: wumengmeng <wu_mengmeng@foxmail.com>
 * Date: 2019/4/26 0026
 * Time: 14:35
 */

namespace HiCommon\Service;

class ShopCheckpointProductService extends BaseService
{

    /**
     * 检测机构-规格参数价目表
     *
     * @param int $n_shop_id
     * @param int $n_use_state
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function api_list_by_shopid($n_shop_id = 0,$n_use_state = 0)
    {
        if($n_shop_id <= 0){
            return hello_error('门店id不能为空');
        }
        if(!in_array($n_use_state,[1,2])){
            //1到站 2代驾
            return hello_error('类型错误');
        }
        if($n_use_state == 1){
            $arr_where_use = ['is_goto_use'=>1];
        }
        else{
            $arr_where_use = ['is_driving_use'=>1];
        }

        $arr_data = [];

        //查询规格配置项
        $arr_where = ['shop_id'=>$n_shop_id];
        $arr_where = $arr_where + $arr_where_use;
        $res = ShopCheckpointServiceSpecsService::get_all_tree_by_shopid($arr_where);
        if($res['state'] != 0){
            return $res;
        }
        $arr_data['specs'] = $res['data'];

        //查询规格配置组合价格
        $arr_where = ['shop_id'=>$n_shop_id];
        $arr_where = $arr_where + $arr_where_use;
        $res = ShopCheckpointServiceSpecsService::get_list_by_shopid_for_dikaer($arr_where);
        if(count($res['data']) <= 0){
            return hello_error('价格获取失败，暂时不能预约');
        }
        $arr_product = [];
        if(count($res['data']) > 0){
            foreach ($res['data'] as $value) {
                $arr = explode(':',$value['ids']);
                sort($arr);
                $value['ids'] = implode(':',$arr);
                $arr_product['p_'.$value['ids']] = [
                  'id'=>$value['ids'],
                  'ids'=>$value['ids'],
                  'name'=>$value['name'],
                  'price'=>$value['price'],
                ];

                if($value['price'] <= 0){
                    return hello_error('检测站未配置价格，暂时不能预约');
                }

            }
        }


        $arr_data['product'] = $arr_product;
        return  hello_success('成功',$arr_data);
    }


}